"""
@Time ： 2024/4/25 23:16
@Auth ： czm
@File ：conftest.py
@IDE ：PyCharm
"""
from sys import platform
import platform
import pytest
from pages.LoginPage import UserLogin
from selenium import webdriver
from pages.DepartmentPage import DeptManagement
from common.db_util import DbConnect, dbinfo
from selenium.webdriver.firefox.options import Options


# @pytest.fixture(scope="session", name="driver")
# def browser():
#     driver = webdriver.Firefox()
#     # driver = webdriver.Chrome()
#     driver.maximize_window()
#     yield driver
#     driver.quit()

@pytest.fixture(scope='session', name='driver')
def browser():
    # 定义一个全局driver
    if platform.system() == 'windows':
        _driver = webdriver.Firefox()
        _driver.maximize_window()
    else:
        # Linux启动
        firefox_options = Options()
        firefox_options.add_argument('--headless')
        firefox_options.add_argument('--no-sandbox')
        firefox_options.add_argument('--disable-gpu')
        firefox_options.add_argument('--disable-dev-shm-usage')
        firefox_options.add_argument('--window-size=1920,1080')
        _driver =webdriver.Firefox(options=firefox_options)
        # _driver = webdriver.Firefox(options=firefox_options)
    yield _driver
    _driver.quit()

@pytest.fixture(scope="session")
def base_url():
    base_url = "http://221.6.105.62:9081"
    return base_url


@pytest.fixture(scope="session")
def user_login(driver, base_url):
    login = UserLogin(driver, base_url)
    return login


@pytest.fixture(scope="session")
def deptment_action(driver):
    deptmentaction = DeptManagement(driver)
    return deptmentaction


@pytest.fixture(scope="session")
def db():
    _db = DbConnect(dbinfo, "enterprise")
    yield _db
    _db.close()


# def pytest_addoption(parser):
#     parser.addoption("--alluredir", action="store", default="test", help="set environment: test,dev,prod")
#     parser.addini("alluredir", type=None, default="--alluredir ./allure_report -v", help="add report_order url in pytest.ini")